package com.pan.alg.leecode;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2022/1/19
 */
public class TreeHasPathSum {

    /**
     *
     * @param root TreeNode类
     * @param sum int整型
     * @return bool布尔型
     */
    public boolean hasPathSum (TreeNode root, int sum) {
        // write code here

        return sumTreeNode(root,sum);

    }

    private boolean sumTreeNode(TreeNode root, int sum) {
        if(root==null){
            return false;
        }else if(root.left==null&&root.right==null){
            return (sum-root.val)==0;
        }

        return sumTreeNode(root.left,sum-root.val)||sumTreeNode(root.right,sum-root.val);


    }

    private  class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }

    public static void main(String[] args) {

    }
}

